/**
 * 文件名：GprsProtocol.java
 *
 * 创建人：Elvin Zhao - 279152260@qq.com
 *
 * 创建时间：2018年7月25日 下午4:44:15
 *
 * 版权所有：FNII
 */
package com.springvision.yuanfeng.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.jeeplus.common.json.JsonTransformer2;
import com.springvision.yuanfeng.device.entity.DeviceMessage;
import com.springvision.yuanfeng.locale.entity.DevStation;

/**
 * [描述信息：说明类的基本功能]
 *
 * @author Elvin Zhao - 279152260@qq.com
 * @version 1.0 Created on 2018年7月25日 下午4:44:15
 */
/**
 * 
 * {"site":"杭州公建中心站","1#":9.26,"3#":9.29,"5#":7.23,"7#":5.26}
 *
 * @author Elvin Zhao - 279152260@qq.com
 * @version 1.0 Created on 2018年7月25日 下午4:49:31
 */
public class GprsProtocol implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String message;

	private DevStation devStation;

	private List<DeviceMessage> deviceMessageList = new ArrayList<DeviceMessage>();

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public DevStation getDevStation() {
		return devStation;
	}

	public void setDevStation(DevStation devStation) {
		this.devStation = devStation;
	}

	public List<DeviceMessage> getDeviceMessageList() {
		return deviceMessageList;
	}

	public void setDeviceMessageList(List<DeviceMessage> deviceMessageList) {
		this.deviceMessageList = deviceMessageList;
	}

	public GprsProtocol() {
		super();
	}

	@Override
	public String toString() {
		return "message---" + message + "------devStation---------" + devStation.toString()
				+ "---------deviceMessageList---------" + deviceMessageList;
	}

	/**
	 * @param message
	 */
	public GprsProtocol(String message) {
		super();
		this.message = message;
		@SuppressWarnings("unchecked")
		Map<String, Object> map = JsonTransformer2.json2Object(message, Map.class);
		this.devStation = new DevStation(map.get("site").toString(), null, null, null, null, null);
		this.devStation.setIsNewRecord(true);
		for (String key : map.keySet()) {
			if (!StringUtils.equals(key, "site")) {
				// System.out.println("#号----" + key + "--value--" +
				// map.get(key).toString());
				this.deviceMessageList.add(new DeviceMessage(key, map.get(key).toString()));
			}
		}
	}

	// TODO 供测试
	public static void main(String args[]) {
		String msg = "{\"site\":\"杭州公建中心站\",\"1#\":9.26,\"3#\":9.29,\"5#\":7.23,\"7#\":5.26}";
		GprsProtocol gProtocol = new GprsProtocol(msg);
		System.out.println(gProtocol.toString());
	}

}
